package com.cjjd.c.feature.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

import com.cjjd.c.R;


/**
 * Created by dadagm on 17/9/11.
 */

public class EditTextDialog extends Dialog implements View.OnClickListener {

    private Context mContext;
    private OnCloseListener listener;
    private String title;
    private EditText mEt;
    private String editHint;
    private String message;
    private TextView mTv;

    public EditText getEt(){
        return  mEt;
    }

    public EditTextDialog(Context context, String title, OnCloseListener listener) {
        super(context, R.style.loading_dialog);

        setContentView(R.layout.dialog_edittext);

        this.mContext = context;
        this.listener = listener;
        this.title=title;
        initView();
    }

    public EditTextDialog setJP(){
        mEt.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
        return this;
    }

    public EditTextDialog(Context context, String title, String editHint, OnCloseListener listener) {
        super(context, R.style.loading_dialog);

        setContentView(R.layout.dialog_edittext);

        this.mContext = context;
        this.listener = listener;
        this.title=title;
        this.editHint=editHint;
        initView();
    }

    private void initView(){
        mEt=(EditText)findViewById(R.id.et);
        findViewById(R.id.ok).setOnClickListener(this);
        findViewById(R.id.quit).setOnClickListener(this);
        mTv=(TextView)findViewById(R.id.title);
        mTv.setText(title);
        if (!TextUtils.isEmpty(editHint)){
            mEt.setHint(editHint);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ok:
                String str=mEt.getText().toString();
                if(TextUtils.isEmpty(str)){
                    this.dismiss();
                    return;
                }
                listener.OnClick(mEt.getText().toString());
                this.dismiss();
                break;
            case R.id.quit:
                this.dismiss();
                break;
        }
    }

    public interface  OnCloseListener{

        public void OnClick(String message);
    }
}
